package com.youpai.platform.biggod.web.api;

import com.youpai.platform.common.entity.resp.BaseResponse;
import com.youpai.platform.biggod.service.service.CategoryService;
import com.youpai.platform.biggod.web.entity.dto.CategoryDto;
import com.youpai.platform.biggod.web.entity.req.CategoryReq;
import com.youpai.platform.biggod.web.entity.resp.CategoryResp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description: 品类相关controller
 * @Author:huanghao
 * @Date:2022/11/12
 */
@Slf4j
@RestController
@RequestMapping(value = "/category")
@Api(value = "CategoryController", tags = "品类相关")
public class CategoryController {
    @Resource
    private CategoryService categoryService;

    @ApiOperation(value = "新建品类")
    @PostMapping(value = "/create")
    public BaseResponse<CategoryResp> createCategory(@RequestBody CategoryReq req) {
        return BaseResponse.success(categoryService.createCategory(req));
    }

    @ApiOperation(value = "修改品类")
    @PostMapping(value = "/update")
    public BaseResponse<CategoryResp> updateCategory(@RequestBody CategoryReq req) {
        return BaseResponse.success(categoryService.updateCategory(req));
    }

    @ApiOperation(value = "获取单个品类详情")
    @PostMapping(value = "/get")
    public BaseResponse<CategoryDto> getCategory(@RequestBody CategoryReq req) {
        return BaseResponse.success(categoryService.getCategory(req));
    }

    @ApiOperation(value = "获取品类列表")
    @PostMapping(value = "/getList")
    public BaseResponse<List<CategoryDto>> getCategoryList(@RequestBody CategoryReq req) {
        return BaseResponse.success(categoryService.getCategoryList(req));
    }

    @ApiOperation(value = "删除品类")
    @PostMapping(value = "/remove")
    public BaseResponse<CategoryResp> removeCategory(@RequestBody CategoryReq req) {
        return BaseResponse.success(categoryService.removeCategory(req));
    }
}
